<?php

namespace app\admin\controller;

use app\common\controller\Backend;

/**
 * 充值管理
 *
 * @icon fa fa-circle-o
 */
class Recharge extends Backend
{

    /**
     * Recharge模型对象
     * @var \app\admin\model\Recharge
     */
    protected $model = null;
    protected $Building = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\Recharge;
        $this->Building = new \app\admin\model\Building;

    }
    public function add()
    {
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            $where_find['num']=$params['num'];
            $Building_find=$this->Building->where($where_find)->find();
            if(empty($Building_find)){
                $this->error('没有此户号');
            }else{
                if($Building_find['money']+$params['money']>0){
//                    if(empty($Building_find['debt_time'])){
                        $update['debt_time']="";
                        $this->Building->where($where_find)->update($update);
//                    }
                }
                $this->Building->where($where_find)->setInc('money', $params['money']);
            }

        }
        return parent::add();
    }


}
